﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Data.Common;
using System.Net.Mail;

public partial class BulletinDetail : System.Web.UI.Page
{
    Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("Application_Data");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Convert.ToBoolean(Session["sAdministrator"].ToString()) == false)
            {
                Response.Redirect("~/AccessDenied.aspx");
            }
            BindData();
        }

    }

    private void BindData()
    {
        string sqlQuery1 = "SELECT * FROM Bulletin WHERE BulletinID = '" + Request.QueryString["BulletinID"].ToString() + "'";
        DataSet ds1 = db.ExecuteDataSet(CommandType.Text, sqlQuery1);
        DataRow dr1 = ds1.Tables[0].Rows[0];

        this.lblCreatedBy.Text = dr1["CreatedBy"].ToString();
        this.lblCreatedDate.Text = dr1["CreatedDate"].ToString();
        this.txtBulletin.Text = dr1["Bulletin"].ToString();
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string sqlQuery1 = "DELETE Bulletin Where BulletinID = '" + Request.QueryString["BulletinID"].ToString() + "'";
        db.ExecuteNonQuery(CommandType.Text, sqlQuery1);

        Response.Redirect("~/Dashboard.aspx");
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string sqlQuery1 = "UPDATE Bulletin SET Bulletin = '"+this.txtBulletin.Text.ToString() + "' Where BulletinID = '" + Request.QueryString["BulletinID"].ToString() + "'";
        db.ExecuteNonQuery(CommandType.Text, sqlQuery1);

        Response.Redirect("~/Dashboard.aspx");
    }
}